import request from '@/utils/request'
import { VisitType, type Visit } from '@/types/visit'

export function getVisits(params: any) {
  return request({
    url: '/api/visits',
    method: 'get',
    params,
  })
}

export function getVisit(id: number) {
  return request({
    url: `/api/visits/${id}`,
    method: 'get',
  })
}

export function createVisit(data: Visit) {
  if (data.visitType == VisitType.PHONE_CALL) {
    data.visitType = 'PHONE_CALL'
  } else if (data.visitType == VisitType.ON_SITE) {
    data.visitType = 'ON_SITE'
  } else if (data.visitType == VisitType.VIDEO_CALL) {
    data.visitType = 'VIDEO_CALL'
  } else if (data.visitType == VisitType.ONLINE_MEETING) {
    data.visitType = 'ONLINE_MEETING'
  } else if (data.visitType == VisitType.EXHIBITION) {
    data.visitType = 'EXHIBITION'
  } else if (data.visitType == VisitType.OTHER) {
    data.visitType = 'OTHER'
  }
  return request({
    url: '/api/visits',
    method: 'post',
    data,
  })
}

export function updateVisit(id: number, data: Visit) {
  if (data.visitType == VisitType.PHONE_CALL) {
    data.visitType = 'PHONE_CALL'
  } else if (data.visitType == VisitType.ON_SITE) {
    data.visitType = 'ON_SITE'
  } else if (data.visitType == VisitType.VIDEO_CALL) {
    data.visitType = 'VIDEO_CALL'
  } else if (data.visitType == VisitType.ONLINE_MEETING) {
    data.visitType = 'ONLINE_MEETING'
  } else if (data.visitType == VisitType.EXHIBITION) {
    data.visitType = 'EXHIBITION'
  } else if (data.visitType == VisitType.OTHER) {
    data.visitType = 'OTHER'
  }
  return request({
    url: `/api/visits/${id}`,
    method: 'put',
    data,
  })
}

export function deleteVisit(id: number) {
  return request({
    url: `/api/visits/${id}`,
    method: 'delete',
  })
}
